#include "button.h"

sButton::sButton(const char* caption_,int x_,int y_, sPanel *parent_)
{
	caption = new char[strlen(caption_)+1];
	strcpy_s(caption,strlen(caption_)+1,caption_);

	SetBounds(x_,y_,200,20);
	SetParent(parent_);

	r = active_gui_engine->panel_r;
	g = active_gui_engine->panel_g;
	b = active_gui_engine->panel_b;
	a = 1.0f;

	nr = active_gui_engine->select_r;;
	ng = active_gui_engine->select_g;;
	nb = active_gui_engine->select_b;
	na = 1.0f;

	isaction = 1;
	isselectably = 1;
	sel = 0;
}

sButton::~sButton()
{
	delete[] caption;
}

void sButton::SetCaption(const char* caption_)
{
	delete[] caption;
	caption = new char[strlen(caption_)+1];
	strcpy_s(caption,strlen(caption_)+1,caption_);
}

const char* sButton::GetCaption()
{
	return caption;
}

void sButton::Process()
{
	sPanel::Process();

//	RoundRect(x + sGUI::cx,y + sGUI::cy,width,height,6);

	if(active_gui_engine)
	{
		glColor4f(active_gui_engine->text_r,active_gui_engine->text_g,active_gui_engine->text_b,1.0f);
		//Color(5,10,15);
		//int w2 = (width - active_gui_engine->font->GetWidth(caption)) / 2;
		//active_gui_engine->font->Text(caption,sGUI::cx + GetX() + width/2 ,sGUI::cy + GetY() + height/2,1,1);
		active_gui_engine->font->StaticDraw(caption,sGUI::cx + GetX() + width/2,sGUI::cy + GetY() + height/2,1,1);
	}
	else
	{
		Text(caption,(float)sGUI::cx + GetX(),(float)sGUI::cy + GetY());
	}
}